package org.webgene.services;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URLEncoder;

import org.apache.http.client.ClientProtocolException;
import org.webgene.util.HTTPGetter;
import org.yaml.snakeyaml.util.UriEncoder;

import play.Logger;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;

import models.meta.Geometry;

public class GeocodingService {
	private String address;
	public GeocodingService(String address){
		this.address = address;
	}
	public Geometry getGeometry() {
		HTTPGetter getter = new HTTPGetter();
		String mapInfoJson = "";
		try {
			
			String uri = "http://maps.google.com/maps/api/geocode/json?address=" + this.address + "&sensor=false";
			UriEncoder encoder = new UriEncoder();
			String url = encoder.encode(uri);
			mapInfoJson = getter.request(url);
			Logger.info("google map request message", mapInfoJson);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		JsonParser parser = new JsonParser();
//		JsonElement jElement = parser.parse(mapInfoJson);
//		Logger.debug("JsonElement", jElement.toString());
//		JsonArray obj = jElement.getAsJsonArray();
//		
//		
		Geometry geometry = new Geometry();
//		Logger.debug("google map request result", obj.toString());
		return geometry;
	}
}
